#include <iostream>
#include <string>

using namespace std;

// 简单写法
string replaceNumber(string s) {
    string result;
    for (int i{}, len = s.size(); i < len; i++) {
        if (s[i] >= '0' && s[i] <= '9') {
            result += "number";
        } else {
            result += s[i];
        }
    }

    return result;
}

// 不使用额外数组
// 首先扩充数组到每个数字字符替换成 "number" 之后的大小
void replaceNumber2(string& s) {
    int count{}, oldSize = s.size();
    for (int i{}; i < oldSize; i++) {
        if (s[i] >= '0' && s[i] <= '9') {
            count++;
        }
    }

    s.resize(oldSize - count + count * 6, '*');
    string num = { "number" };
    int j = s.size() - 1;
    for (int i{oldSize - 1}; i >= 0; i--) {
        if (s[i] >= '0' && s[i] <= '9') {
            int n = num.size();
            while (n) {
                cout << j << " " << n << "\n";
                s[j--] = num[n - 1];
                n--;
                cout << s << "\n";
            }
        } else {
            s[j] = s[i];
            cout << s << "\n";
            // 这里i不用再移动了
            j--;
        }
    }
}

int main() {
    string s { "a1b2c3" };
    cout << "origin: " << s << "\n";
    // cout << "after: " << replaceNumber(s) << "\n";

    replaceNumber2(s);
    cout << "after: " << s << "\n";

    return 0;
}
